﻿<UserControl x:Class="TfsBuildManager.Views.MainView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Controls="clr-namespace:TfsBuildManager.Controls;assembly=TFSBuildManager.Controls" xmlns:Views="clr-namespace:TfsBuildManager.Views" mc:Ignorable="d" 
             HorizontalContentAlignment="Stretch"
             VerticalContentAlignment="Stretch" Loaded="OnLoaded">

    <UserControl.Resources>
        <Views:EnumMatchToBooleanConverter x:Key="enumConverter" />
    </UserControl.Resources>

    <Grid Background="#FFC4D6E6">
        <Grid.RowDefinitions>
            <RowDefinition Height="25"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition  Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal" Background="#FF8398AA">
            <Button Name="btnViewBuildResources" Command="{Binding GenerateBuildResourcesCommand}" Width="18" Height="18" Margin="10,0,0,0">
                <Image Source="Graphics/dgml.png" ToolTip="Generate Build Resources Dependency Graph (DGML)"/>
            </Button>
            <Button Name="btnRefresh" Command="{Binding RefreshCurrentView}" Width="18" Height="18" Margin="6,0,0,0">
                <Image Source="Graphics/refresh.png" ToolTip="Refresh Current View"/>
            </Button>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Background="#FF8398AA" HorizontalAlignment="Right">
            <Label Name="lblVersion" Foreground="White">Version</Label>
        </StackPanel>
        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="17"></RowDefinition>
                <RowDefinition Height="25"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="12*" MinWidth="100"></ColumnDefinition>
                <ColumnDefinition Width="88*"/>
                <ColumnDefinition Width="146*" MinWidth="100"></ColumnDefinition>
                <ColumnDefinition Width="145*" MinWidth="100"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <TextBlock Text="Show" Margin="10,2,0,0" Grid.ColumnSpan="2" />
            <ComboBox Name="SelectedBuildViewCombo" Grid.Row="1" ItemsSource="{Binding BuildViews}" SelectedValuePath="Value" DisplayMemberPath="Name"  Margin="10,2,10,0"
                      SelectedValue="{Binding Path=SelectedBuildView}" Grid.ColumnSpan="2">
            </ComboBox>
            <TextBlock Text="Build Controller" Grid.Column="2" Margin="10,2,0,0"/>
            <ComboBox Name="ControllerCombo" Grid.Column="2" Grid.Row="1" ItemsSource="{Binding Controllers}"  Margin="10,2,0,0"/>
            <TextBlock Text="Team Project" Grid.Column="3" Margin="10,2,0,0" />
            <ComboBox Name="TeamProjectCombo" Grid.Column="3" Grid.Row="1" ItemsSource="{Binding TeamProjects}"  Margin="10,2,10,0"/>
        </Grid>

        <Grid Grid.Row="2" Name="BuildDefinitionGrid" Visibility="{Binding Path=BuildDefinitionViewVisible}" Margin="0,10,0,0" Background="White">
            <Grid.Resources>
                <Style TargetType="{x:Type GridViewColumnHeader}">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    <Setter Property="Margin" Value="5,0,0,0"/>
                </Style>
            </Grid.Resources>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid Grid.Row="0" Name="BuildDefinitionFilter" Visibility="{Binding Path=BuildDefinitionViewVisible}" Margin="0,0,0,0" VerticalAlignment="Center" Background="#FFC4D6E6">
                    <StackPanel Orientation="Horizontal" Margin="10,0,5,0" VerticalAlignment="Center">
                        <CheckBox IsChecked="{Binding IncludeDisabledBuildDefinitions}" VerticalAlignment="Center"></CheckBox>
                        <TextBlock Text="Include Disabled Builds" Margin="5,0,0,0" ></TextBlock>
                    </StackPanel>
                </Grid>
                <Controls:SortableListView Grid.Row="1" Padding="0" BorderThickness="1" x:Name="BuildDefinitionList" ItemsSource="{Binding BuildDefinitions}" IsManipulationEnabled="False" BorderBrush="LightGray" VerticalAlignment="Stretch">
                    <ListView.ItemContainerStyle>
                        <Style TargetType="{x:Type ListViewItem}">
                            <Setter Property="ToolTip" Value="{Binding Path=Description}" />
                            <Setter Property="FontStyle" >
                                <Setter.Value>
                                    <Binding Path="Enabled">
                                        <Binding.Converter>
                                            <Views:BoolToFontStyleConverter/>
                                        </Binding.Converter>
                                    </Binding>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="FontWeight" >
                                <Setter.Value>
                                    <Binding Path="Enabled">
                                        <Binding.Converter>
                                            <Views:BoolToFontWeightConverter/>
                                        </Binding.Converter>
                                    </Binding>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ListView.ItemContainerStyle>
                    <ListView.Resources>
                        <DataTemplate x:Key="NameTemplate">
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                                <TextBlock Text="{Binding Name}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                            </StackPanel>
                        </DataTemplate>
                        <DataTemplate x:Key="TeamProjectTemplate">
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                                <TextBlock Text="{Binding TeamProject}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                            </StackPanel>
                        </DataTemplate>
                        <DataTemplate x:Key="ContinuousIntegrationTypeTemplate">
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                                <TextBlock Text="{Binding ContinuousIntegrationType}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                            </StackPanel>
                        </DataTemplate>
                        <DataTemplate x:Key="BuildControllerTemplate">
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                                <TextBlock Text="{Binding BuildController}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                            </StackPanel>
                        </DataTemplate>
                        <DataTemplate x:Key="ProcessTemplate">
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                                <TextBlock Text="{Binding Process}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                            </StackPanel>
                        </DataTemplate>
                        <DataTemplate x:Key="DefaultDropLocation">
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                                <TextBlock Text="{Binding DefaultDropLocation}" Margin="3,0,0,1" VerticalAlignment="Bottom"/>
                            </StackPanel>
                        </DataTemplate>
                        <Style TargetType="{x:Type GridViewColumnHeader}">
                            <Setter Property="Padding" Value="5,0" />
                            <Setter Property="HorizontalContentAlignment" Value="Left" />
                        </Style>                        

                    </ListView.Resources>
                    <Controls:SortableListView.ContextMenu>
                        <ContextMenu>
                            <MenuItem Command="{Binding QueueBuildsCommand}" Header="Queue"/>
                            <Separator/>
                            <MenuItem Command="{Binding EnableCommand}" Header="Enable">
                                <MenuItem.Icon>
                                    <Image Source="Graphics/menu_enable.png" Width="16" Height="16" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Command="{Binding DisableCommand}" Header="Disable">
                                <MenuItem.Icon>
                                    <Image Source="Graphics/manu_disable.png" Width="16" Height="16" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Command="{Binding DeleteCommand}" Header="Delete">
                                <MenuItem.Icon>
                                    <Image Source="Graphics/menu_delete.png" Width="16" Height="16" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <Separator/>
                            <MenuItem Header="Change">
                                <MenuItem Command="{Binding ChangeBuildControllerCommand}" Header="Build Controller">
                                    <MenuItem.Icon>
                                        <Image Source="Graphics/controller.png" Width="16" Height="16" />
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem Command="{Binding ChangeBuildTemplateCommand}" Header="Build Process Template">
                                <MenuItem.Icon>
                                    <Image Source="Graphics/menu_changetemplate.png" Width="16" Height="16" />
                                </MenuItem.Icon>
                            </MenuItem>

                                <MenuItem Command="{Binding ChangeDefaultDropLocationCommand}" Header="Drop Location">
                                    <MenuItem.Icon>
                                        <Image Source="Graphics/Drop.png" Width="16" Height="16" />
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem Command="{Binding SetRetentionPoliciesCommand}" Header="Retention Policies">
                                <MenuItem.Icon>
                                    <Image Source="Graphics/retention.png" Width="16" Height="16" />
                                </MenuItem.Icon>
                            </MenuItem>
                            </MenuItem>
                            <MenuItem Command="{Binding CloneBuildsCommand}" Header="Clone to Branch">
                                <MenuItem.Icon>
                                    <Image Source="Graphics/clone.png" Width="16" Height="16" />
                                </MenuItem.Icon>
                            </MenuItem>
                          <MenuItem Command="{Binding EditBuildDefinitionCommand}" Header="Edit Build Definition"/>
                        </ContextMenu>
                    </Controls:SortableListView.ContextMenu>
                    
                    <ListView.View>
                        <GridView>
                            <Controls:SortableGridViewColumn Header="Name" SortPropertyName="Name" IsDefaultSortColumn="True" CellTemplate="{StaticResource NameTemplate}"/>
                            <Controls:SortableGridViewColumn Header="TeamProject" SortPropertyName="TeamProject" IsDefaultSortColumn="False" CellTemplate="{StaticResource TeamProjectTemplate}"/>
                            <Controls:SortableGridViewColumn Header="ContinuousIntegrationType" SortPropertyName="ContinuousIntegrationType" IsDefaultSortColumn="False" CellTemplate="{StaticResource ContinuousIntegrationTypeTemplate}"/>
                            <Controls:SortableGridViewColumn Header="Controller" SortPropertyName="BuildController" IsDefaultSortColumn="False" CellTemplate="{StaticResource BuildControllerTemplate}"/>
                            <Controls:SortableGridViewColumn Header="Process" SortPropertyName="Process" IsDefaultSortColumn="False" CellTemplate="{StaticResource ProcessTemplate}"/>
                            <Controls:SortableGridViewColumn Header="DefaultDropLocation" SortPropertyName="DefaultDropLocation" IsDefaultSortColumn="False" CellTemplate="{StaticResource DefaultDropLocation}"/>
                        </GridView>
                    </ListView.View>
                </Controls:SortableListView>
            </Grid>
        </Grid>

        <TabControl Grid.Row="2" Grid.ColumnSpan="3" Name="BuildGrid" Visibility="{Binding Path=BuildsViewVisible}" Margin="0,10,0,0">
            <TabItem Name="Queued" Header="Queued" IsSelected="{Binding Path=SelectedBuildFilter, Mode=TwoWay, Converter={StaticResource enumConverter}, ConverterParameter=Queued}">
                <Views:BuildsGrid x:Name="RunningBuilds">
                    <Views:BuildsGrid.ContextMenu>
                        <ContextMenu>
                            <MenuItem Command="{Binding ShowQueuedDetailsCommand}" Header="Open"/>
                            <MenuItem Command="{Binding StopBuildCommand}" Header="Stop / Cancel">
                                <MenuItem.Icon>
                                    <Image Source="Graphics/Stopped.ico" Width="16" Height="16" />
                                </MenuItem.Icon>
                            </MenuItem>
                        </ContextMenu>
                    </Views:BuildsGrid.ContextMenu>
                </Views:BuildsGrid>
            </TabItem>
            <TabItem Name="Completed" Header="Completed" IsSelected="{Binding Path=SelectedBuildFilter, Mode=TwoWay, Converter={StaticResource enumConverter}, ConverterParameter=Completed}">
                <DockPanel Background="#FFC4D6E6" Margin="-4,-4,-4,0">
                    <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" DockPanel.Dock="Top" Margin="2,2,2,2">
                        <Label>Date Filter</Label>
                        <ComboBox Name="CompletedBuildsDateFilter" ItemsSource="{Binding DateFilters}" SelectedValuePath="Value" DisplayMemberPath="Name" SelectedValue="{Binding Path=SelectedDateFilter}" Width="120" HorizontalAlignment="Right"/>
                    </StackPanel>
                    <Views:BuildsGrid x:Name="CompletedBuilds" DockPanel.Dock="Bottom">
                       
                        <Views:BuildsGrid.ContextMenu>
                            <ContextMenu>
                                <MenuItem Command="{Binding ShowDetailsCommand}" Header="Open">

                                </MenuItem>                               
                                <MenuItem Command="{Binding DeleteBuildCommand}" Header="Delete">
                                    <MenuItem.Icon>
                                        <Image Source="Graphics/menu_delete.png" Width="16" Height="16" />
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem Command="{Binding OpenDropFolderCommand}" Header="Open Drop Folder">
                                    <MenuItem.Icon>
                                        <Image Source="Graphics/Drop.png" Width="16" Height="16" />
                                    </MenuItem.Icon>

                                </MenuItem>
                                <MenuItem Command="{Binding SetBuildQualityCommand}" Header="Set Build Quality">
                                    <MenuItem.Icon>
                                        <Image Source="Graphics/Edit.png" Width="16" Height="16" />
                                    </MenuItem.Icon>
                                </MenuItem>

                                <MenuItem Command="{Binding RetainIndefinitelyCommand}" Header="Retain Indefinitely">
                                    <MenuItem.Icon>
                                        <Image Source="Graphics/lock24.png" Width="16" Height="16" />
                                    </MenuItem.Icon>
                                </MenuItem>
                               <MenuItem Command="{Binding BuildNotesCommand}" Header="Experimental: Build Notes">
                                    <MenuItem.Icon>
                                        <Image Source="Graphics/BuildNotes.png" Width="16" Height="16" />
                                    </MenuItem.Icon>
                                </MenuItem>
                              <MenuItem Command="{Binding EditBuildDefinitionCommand}" Header="Edit Build Definition"/>
                            </ContextMenu>
                        </Views:BuildsGrid.ContextMenu>
                    </Views:BuildsGrid>
                </DockPanel>
            </TabItem>
        </TabControl>
        <Views:ProcessTemplatesGrid Grid.Row="2" Grid.ColumnSpan="3" x:Name="ProcessTemplateGrid" Visibility="{Binding Path=BuildProcessTemplateViewVisible}" Margin="0,10,0,0">
            <Views:ProcessTemplatesGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="{Binding SetDefaultBuildTemplateCommand}" Header="Set As Default">
                        <MenuItem.Icon>
                            <Image Source="Graphics/SetDefault.png" Width="16" Height="16" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Command="{Binding AddBuildProcessTemplateCommand}" Header="Add to Team Project(s)">
                        <MenuItem.Icon>
                            <Image Source="Graphics/Menu_Enable.png" Width="16" Height="16" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Command="{Binding RemoveBuildProcessTemplateCommand}" Header="Remove from Team Project(s)">
                        <MenuItem.Icon>
                            <Image Source="Graphics/Menu_Delete.png" Width="16" Height="16" />
                        </MenuItem.Icon>
                    </MenuItem>

                </ContextMenu>
            </Views:ProcessTemplatesGrid.ContextMenu>

        </Views:ProcessTemplatesGrid>
    </Grid>
</UserControl>
